package com.katze.common.ws.handler;

import com.katze.common.ws.core.UserChannelGroup;
import io.netty.channel.ChannelFuture;
import io.netty.util.concurrent.GenericFutureListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.function.Consumer;

public interface JwtAuthHandler extends GenericFutureListener<ChannelFuture> {
    Logger log = LoggerFactory.getLogger(JwtAuthHandler.class);

    Object doAuthentication(String token, Consumer<Serializable> con) throws IllegalAccessError;

    @Override
    default void operationComplete(ChannelFuture future) throws Exception {
        Serializable user = future.channel().attr(UserChannelGroup.USER).get();
        log.info("{}用户消息推送{}", user, future.isSuccess()? "成功":"失败");
        future.removeListener(this);
    }

}
